//
//  GYMineOrderInfoListCell.m
//  GYDemo
//
//  Created by mac on 2018/4/2.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineOrderInfoListCell.h"
#import "Head.h"

@interface GYMineOrderInfoListCell()<GCAdaptLabelDelegate>
@property (nonatomic,strong) UIView *backV;

@end

@implementation GYMineOrderInfoListCell
#pragma mark - getter and setter
-(UIView *)backV
{
    if (!_backV) {
        _backV = [UIView new];
        _backV.width = WF_UI_VIEW_WIDTH;
        _backV.height = WFCGFloatY(78);
        _backV.backgroundColor = RGBACOLOR(247, 247, 247, 0.5);
    }
    return _backV;
}

-(UIImageView *)imageIV
{
    if (!_imageIV) {
        _imageIV = [UIImageView new];
        _imageIV.frame = WFCGRectMake(13, 8.5, 60, 60);
        _imageIV.backgroundColor = Main_Color_BG;
    }
    return _imageIV;
}
-(GCAdaptLabel *)nameLB
{
    if (!_nameLB) {
        _nameLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(145.5)];
        _nameLB.x = WFCGFloatX(88.5);
        _nameLB.y = WFCGFloatY(8.5);
        _nameLB.width = WFCGFloatX(130.5);
        _nameLB.height = WFCGFloatY(20);
        _nameLB.font = SYSTEMFONT(14);
        _nameLB.textColor = Main_Color_Black;
        _nameLB.delegate = self;
    }
    return _nameLB;
}

-(GCAdaptLabel *)typeLB
{
    if (!_typeLB) {
        _typeLB = [[GCAdaptLabel alloc]initWithMaxWidth:WFCGFloatX(60)];
        _typeLB.x = WFCGFloatX(166);
        _typeLB.y = WFCGFloatY(11.5);
        _typeLB.width = WFCGFloatX(60);
        _typeLB.height = WFCGFloatY(14);
        _typeLB.font = SYSTEMFONT(10);
        _typeLB.textColor = Main_Color_Red;
        [WFFunctions WFUIaddbordertoView:_typeLB radius:WFCGFloatY(3) width:0.7f color:Main_Color_Red];
        _typeLB.delegate = self;
    }
    return _typeLB;
}

-(UILabel *)priceLB
{
    if (!_priceLB) {
        _priceLB = [[UILabel alloc]init];
        _priceLB.x = WF_UI_VIEW_WIDTH - WFCGFloatX(100 + 13);
        _priceLB.y = WFCGFloatY(10);
        _priceLB.width = WFCGFloatX(100);
        _priceLB.height = WFCGFloatY(20);
        _priceLB.textColor = Main_Color_Black;
        _priceLB.font = SYSTEMFONT(14);
        _priceLB.textAlignment = NSTextAlignmentRight;
    }
    return _priceLB;
}

-(UILabel *)countLB
{
    if (!_countLB) {
        _countLB = [[UILabel alloc]init];
        _countLB.x = WF_UI_VIEW_WIDTH - WFCGFloatX(18 + 70);
        _countLB.y = WFCGFloatY(52);
        _countLB.width = WFCGFloatX(70);
        _countLB.height = WFCGFloatY(16.5);
        _countLB.textColor = Main_Color_Gray;
        _countLB.font = SYSTEMFONT(12);
        _countLB.textAlignment = NSTextAlignmentRight;
    }
    return _countLB;
}



-(void)setModel:(GYMineOrderInfoListModel *)model
{
    _model = model;
    _nameLB.text = model.goodname;
    _typeLB.text = @"一级";

    [_imageIV sd_setImageWithURL:[NSURL URLWithString:_model.imgpath] placeholderImage:[UIImage imageNamed:@"default_goods"]];
    
    NSString *unit = @"件";
    NSString *counts = [NSString stringWithFormat:@"x %ld%@",(long)_model.num,unit];
    _countLB.text = counts;
    NSString *priceUnit = [NSString stringWithFormat:@"%.2ld元/%@",_model.price,unit];
    _priceLB.text = priceUnit;
}
#pragma mark - method
+(CGFloat)finalHeight
{
    return WFCGFloatY(78);
}
#pragma mark - life
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.backV];
        [self.contentView addSubview:self.imageIV];
        [self.contentView addSubview:self.nameLB];
        [self.contentView addSubview:self.typeLB];
        [self.contentView addSubview:self.priceLB];
        [self.contentView addSubview:self.countLB];
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _typeLB.x = _nameLB.right + WFCGFloatX(5);
    _typeLB.centerY = _nameLB.centerY;
}
#pragma mark - delegate
-(void)callback:(id)sender
{
    [self layoutSubviews];
}
@end
